/**************************************功能介绍***********************************
Copyright:			
Date     :			
Author   :厉长川			
Version  :2022.10.13 v1			
Description:图像数据处理模块		
*********************************************************************************/

`include "param.v"

module process( 
    input				clk		   ,//pclk
    input				rst_n	   ,//复位信号
    input		[15:0]	rgb_din    ,//rgb数据输入
    input		        rgb_valid  ,//rgb数据有效标志  
    input               rgb_eop     ,
    input               rgb_sop     ,

    output		[15:0]	pro_dout   ,//处理完成输出
    output		     	pro_valid   ,//处理完成输出有效标志
    output              pro_sop     ,
    output              pro_eop
);		
    //中间信号定义						 			 
    wire        [7:0]   gray_dout  ;//灰度转换输出
    wire                gray_valid ;//灰度转换输出有效标志             		 
    wire        [7:0]   gus_dout   ;//高斯滤波输出
    wire                gus_valid  ;//高斯滤波输出有效标志
    wire                bin_dout   ;//二值化输出
    wire                bin_valid  ;//二值化输出有效标志
    wire                sobel_dout ;//边缘检测输出
    wire                sobel_valid;//边缘检测输出有效标志
    wire                gray_eop    ;
    wire                gray_sop    ;
    wire                gus_eop     ;
    wire                gus_sop     ;
    wire                bin_eop     ;
    wire                bin_sop     ;
    wire                sobel_eop   ;
    wire                sobel_sop   ;

    //灰度转换模块
    rgb2gray u_rgb2gray(
    	.clk         (clk         ),
        .rst_n       (rst_n       ),
        .rgb_valid   (rgb_valid   ),
        .rgb_din     (rgb_din     ),
        .rgb_sop    (rgb_sop),
        .rgb_eop    (rgb_eop),
        .gray_dout   (gray_dout   ),
        .gray_valid  (gray_valid  ),
        .gray_sop   (gray_sop),
        .gray_eop   (gray_eop)
    );
    
    //高斯滤波模块
    gus_filter u_gus_filter(
    	.clk         (clk         ),
        .rst_n       (rst_n       ),
        .gray_din    (gray_dout   ),
        .gray_sop    (gray_sop),
        .gray_eop    (gray_eop),
        .gray_valid  (gray_valid  ),
        .gus_dout    (gus_dout    ),
        .gus_valid   (gus_valid   ),
        .gus_sop     (gus_sop),
        .gus_eop     (gus_eop)
    );

    //二值化模块
    bin u_bin(
    	.clk         (clk         ),
        .rst_n       (rst_n       ),
        .gus_din     (gus_dout    ),
        .gus_valid   (gus_valid   ),
        .gus_eop    (gus_eop),
        .gus_sop    (gus_sop),
        .bin_dout    (bin_dout    ),
        .bin_valid   (bin_valid   ),
        .bin_sop     (bin_sop),
        .bin_eop    (bin_eop)
    );
    
    //边缘检测模块
    sobel u_sobel(
    	.clk         (clk         ),
        .rst_n       (rst_n       ),
        .bin_din     (bin_dout    ),
        .bin_eop    (bin_eop),
        .bin_sop    (bin_sop),
        .bin_valid   (bin_valid   ),
        .sobel_dout  (sobel_dout  ),
        .sobel_valid (sobel_valid ),
        .sobel_eop  (sobel_eop),
        .sobel_sop  (sobel_sop)
    );

    //输出控制
    `ifdef GRAY_OUT //输出灰度化图像
        assign pro_dout = {gray_dout[7:3], gray_dout[7:2], gray_dout[7:3]};//灰度输出
        assign pro_valid = gray_valid;//灰度输出有效标志
        assign  pro_sop = gray_sop  ;
        assign  pro_eop = gray_eop  ;
    `endif 
    
    `ifdef GUS_OUT  //输出高斯滤波图像
        assign pro_dout = {gus_dout[7:3], gus_dout[7:2], gus_dout[7:3]};//高斯滤波输出
        assign pro_valid = gus_valid;//高斯滤波输出有效标志
        assign  pro_sop = gus_sop  ;
        assign  pro_eop = gus_eop  ;
    `endif 

    `ifdef BIN_OUT  //输出二值化图像
        assign pro_dout = {16{bin_dout}};//二值化输出
        assign pro_valid = bin_valid;//二值化输出有效标志
        assign  pro_sop = bin_sop  ;
        assign  pro_eop = bin_eop  ;
    `endif 

    `ifdef SOBEL_OUT//输出边缘检测图像
        assign pro_dout = {16{sobel_dout}};//边缘检测输出
        assign pro_valid = sobel_valid;//边缘检测输出有效标志
        assign  pro_sop = sobel_sop  ;
        assign  pro_eop = sobel_eop  ;
    `endif 

    `ifdef NO_PRO   //输出rgb图像
        assign pro_dout = rgb_din;//rgb输出
        assign pro_valid = rgb_valid;//rgb输出有效标志
        assign  pro_sop = rgb_sop  ;
        assign  pro_eop = rgb_eop  ;
    `endif
                        
endmodule
